package com.woniu.gf.pawn.comm.core.util;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;

import java.security.Key;
import java.util.Date;
import java.util.Map;

/**
 * @BelongsProject: spring-cloud
 * @BelongsPackage: com.woniu.gf.pawn.comm.core.util
 * @Author: rofus
 * @CreateTime: 2020-09-29 13:06
 * @Description:
 */
public class JwtUtil {
    private static String sort="ahsdjashdjqwldkalskdaksjdaksjdsajdalsdkasdjksdjkajd";

    public static String createToken(Map<String, Object> map,Integer sec){
        Key key= Keys.hmacShaKeyFor(sort.getBytes());
        return Jwts.builder().setClaims(map)
                .setExpiration(new Date(System.currentTimeMillis()+sec*1000))
                .signWith(key)
                .compact();
    }
    public static Map<String, Object> parseToken(String jwt){
        Key key= Keys.hmacShaKeyFor(sort.getBytes());
        return Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(jwt).getBody();
    }
}
